//
//  CZBaseViewController.swift
//  weibo123456
//
//  Created by 露露 on 16/6/8.
//  Copyright © 2016年 lulu. All rights reserved.
//

import UIKit

class CZBaseViewController: UITableViewController,CZVisitorViewDelegate {
    /// 用户是否登录
    var userLogin = CZUserAccount.userLogin
    

//    var userLogin = false
    
    override func loadView() {
        userLogin ? super.loadView() : setupVistorView()
    }
     /// 设置访客视图
    func setupVistorView(){
        
      view = visitorView
//        view.backgroundColor = UIColor.brownColor()
      // 设置代理,
        visitorView.delegate = self
        // 设置导航栏按钮
        // 左边
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style:UIBarButtonItemStyle.Plain , target: self, action: "visitorViewRegisterClick")
        
        // 设置导航栏按钮
        // 右边
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        
        if self is CZHomeViewController {
            // 设置动画
            visitorView.startRotationAnimation()
            // 程序退到后台会进入前台都会发送通知.
            // 注册通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            
 

        }
        
        if self is CZMessareViewController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")

        }
        if self is CZDiscoveryViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }
        if self is CZProfileViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            
        }
        
        
    }
    
    // MARK: - 通知presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    // 退到后台
    func didEnterBackground() {
        // 停止转轮旋转
        visitorView.pauseAnimation()

    }
    // 进入前台
    func didBecomeActive() {
        // 恢复转轮旋转
       
        visitorView.resumeAnimation()
    }
   // 实现代理方法
    // 注册按钮被点击
    func visitorViewRegisterClick(){
//        print(__FUNCTION__)

        
    }
    
    // 实现代理方法
    // 登陆按钮被点击
    func visitorViewLoginClick(){
//        print(__FUNCTION__)

         // 创建登陆界面
        let oauthVC = CZoauthViewController()
        // 弹出登陆界面,包装导航控制器
        presentViewController(UINavigationController(rootViewController:oauthVC), animated: true, completion: nil)
        
   
      
        
    }
    
    
     // 懒加载 访客视图
    lazy var visitorView : CZVistorView = CZVistorView()
}
